package com.principle.ocp;

public class Ocp {
    public static void main(String[] args) {
        //使用看看存在的问题
        GraphicEditor graphicEditor = new GraphicEditor();
        graphicEditor.drawShape(new Rectangle());
        graphicEditor.drawShape(new Circle());
    }
}

// 这是一个用于绘图的类
class GraphicEditor {
    // 接收Shape对象，然后根据type，来绘制不同的图形
    public void drawShape(Shape s){
        if(s.m_type == 1){
           drawRectangle();
        }else if (s.m_type == 2){
            drawCircle();
        }
    }
    public void drawRectangle(){
        System.out.println("绘制矩形");
    }
    public void drawCircle(){
        System.out.println("绘制圆形");
    }
}

class Shape {
    int m_type;
}

class Rectangle extends Shape {
    Rectangle(){
        super.m_type=1;
    }
}

// 新增加的功能
class Circle extends Shape {
    Circle() {
        super.m_type = 2;
    }
}

